package com.zq.it.dao.impl.exam;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.zq.it.dao.exam.TTaskmodelDAO;
import com.zq.it.dao.impl.BaseDao;
import com.zq.it.pojo.exam.TTaskmodel;

public class TTaskmodelDAOImpl extends BaseDao<TTaskmodel> implements TTaskmodelDAO {

	private static final Logger log = LoggerFactory
			.getLogger(TTaskmodelDAOImpl.class);
	// property constants
	public static final String MODEL_NAME = "modelName";
	public static final String UPLOAD_TIME = "uploadTime";
	public static final String TECH_STYLE = "techStyle";
	public static final String UPLOADER = "uploader";
	public static final String MODEL_URL = "modelUrl";
	public static final String DEMOTE_MODEL_URL = "demoteModelUrl";
	public static final String ANWSER_MODEL_URL = "anwserModelUrl";
	public static final String EXTEND_FIELD = "extendField";

	@Override
	public void save(TTaskmodel transientInstance) {
		log.debug("saving TTaskmodel instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	@Override
	public void delete(TTaskmodel persistentInstance) {
		log.debug("deleting TTaskmodel instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	@Override
	public TTaskmodel findById(Long id) {
		log.debug("getting TTaskmodel instance with id: " + id);
		try {
			TTaskmodel instance = (TTaskmodel) getHibernateTemplate()
					.get("com.zq.it.pojo.exam.TTaskmodel", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	@Override
	public List findByExample(TTaskmodel instance) {
		log.debug("finding TTaskmodel instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	@Override
	public List findByProperty(String propertyName, Object value) {
		log.debug("finding TTaskmodel instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from TTaskmodel as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	@Override
	public List findByModelName(Object modelName) {
		return findByProperty(MODEL_NAME, modelName);
	}

	@Override
	public List findByUploadTime(Object uploadTime) {
		return findByProperty(UPLOAD_TIME, uploadTime);
	}

	@Override
	public List findByTechStyle(Object techStyle) {
		return findByProperty(TECH_STYLE, techStyle);
	}

	@Override
	public List findByUploader(Object uploader) {
		return findByProperty(UPLOADER, uploader);
	}

	@Override
	public List findByModelUrl(Object modelUrl) {
		return findByProperty(MODEL_URL, modelUrl);
	}

	@Override
	public List findByDemoteModelUrl(Object demoteModelUrl) {
		return findByProperty(DEMOTE_MODEL_URL, demoteModelUrl);
	}

	@Override
	public List findByAnwserModelUrl(Object anwserModelUrl) {
		return findByProperty(ANWSER_MODEL_URL, anwserModelUrl);
	}

	@Override
	public List findByExtendField(Object extendField) {
		return findByProperty(EXTEND_FIELD, extendField);
	}

	@Override
	public List findAll() {
		log.debug("finding all TTaskmodel instances");
		try {
			String queryString = "from TTaskmodel";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	@Override
	public void update(TTaskmodel instance) {
		log.debug("attaching dirty TTaskmodel instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	@Override
	public List findByHql(String hql) {
		log.debug("finding TTaskmodel instances by Hql");
		try {
			return getHibernateTemplate().find(hql);
		} catch (RuntimeException re) {
			log.error("find by Hql failed", re);
			throw re;
		}
	}
}